import { LocalStorage } from '@/utils/storage'
import { APP_THEME } from '../mutation-types';

export type Themes = 'dark' | 'light' | 'mix';

export interface SettingStateType {
  // 主题
  theme: Themes;
}

const cacheTheme = LocalStorage.get(APP_THEME)

const state: SettingStateType = {
  theme:
    (cacheTheme === 'dark' && 'dark') ||
    (cacheTheme === 'light' && 'light') ||
    (cacheTheme === 'mix' && 'mix') ||
    'dark',
};

const mutations = {
  // 切换主题
  themeChanged(state: SettingStateType, payload: { theme: Themes }): void {
    state.theme = payload.theme;
    LocalStorage.set(APP_THEME, payload.theme)
  },
};
const actions = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
